import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "../views/Home";
//剩下的可以进行路由懒加载（在路由被访问时才会引入组件）

import AppIndex from "../components/home/AppIndex";
import Login from "../views/Login";
import LibraryIndex from "../components/library/LibraryIndex";

import Register from "../views/Register";

import ArticleEditor from "../components/Blog/ArticleEditor";
import Articles from "../components/Blog/Articles";
import ArticleDetails from "../components/Blog/ArticleDetails";
import ArticleManagement from "../components/Blog/ArticleManagement";
import LibraryManagement from "../components/library/LibraryManagement";

Vue.use(VueRouter)

const routes = [
  {
    //在已登录状态下访问 http://localhost:8081/ 会跳转到 /index，否则会跳转到登录页面。
    path: '/',
    name: 'index',
    redirect: '/index',
    component: AppIndex,
    meta: {
      requireAuth: true
    }
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    // home页面并不需要被访问.作为其所有子组件的公共部分
    redirect: '/index',
    children: [
      {
        path: '/index',
        name: 'AppIndex',
        component: AppIndex,
      },
      {
        path: '/library',
        name: 'Library',
        component: LibraryIndex,
        meta: {
          requireAuth: true
        }
      },
      {
        path: '/admin/libraryManagement',
        name: 'LibraryManagement',
        component: LibraryManagement,
        meta: {
          requireAuth: true
        }
      },
      {
        path: '/blog',
        name: 'blog',
        component: Articles,
        meta: {
          requireAuth: true
        }
      },
      {
        path: '/blog/article',
        name: 'Article',
        component: ArticleDetails
      },
      {
        path: '/admin/editor',
        name: 'ArticleEditor',
        component: ArticleEditor,
        meta: {
          requireAuth: true
        }
      },
      {
        path: '/admin/ArticleManagement',
        name: 'ArticleManagement',
        component: ArticleManagement,
        meta: {
          requireAuth: true
        }
      },

    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
